package test;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

public class A2 {
//	protected static String testUrl = "http://gw.api.tbsandbox.com/router/rest";//沙箱环境调用地址
//	protected static String appkey = "test";
//	protected static String secret = "test";
////	
	protected static String testUrl = "http://gw.api.taobao.com/router/rest";//沙箱环境调用地址
	protected static String appkey = "12232777";
	protected static String secret = "a6ab6a8e090d9019eba130342d995ea7";
	public static String testUserGet(){
    	 TreeMap<String, String> apiparamsMap = new TreeMap<String, String>();
    	 apiparamsMap.put("format", "xml");
    	 apiparamsMap.put("method", "taobao.user.get");
    	 apiparamsMap.put("sign_method","md5");
    	 apiparamsMap.put("app_key",appkey);
    	 apiparamsMap.put("v", "2.0");
    	 //apiparamsMap.put("session",request.getParameter("session"));他用型需要sessionkey
    	 String timestamp =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    	 apiparamsMap.put("timestamp",timestamp);
    	 apiparamsMap.put("fields","user_id,uid,nick");//需要获取的字段
    	 apiparamsMap.put("nick","liuxiaozhen012");
    	 //生成签名
    	 String sign = Util.md5Signature(apiparamsMap,secret);
    	 apiparamsMap.put("sign", sign);
    	 StringBuilder param = new StringBuilder();
    	 for (Iterator<Map.Entry<String, String>> it = apiparamsMap.entrySet()
    	 .iterator(); it.hasNext();) {
        	 Map.Entry<String, String> e = it.next();
        	 param.append("&").append(e.getKey()).append("=").append(e.getValue());
    	 }
    	 return param.toString().substring(1);
	}
	/**
	 * 二行制转字符串
	 */
	private static String byte2hex(byte[] b) {

		StringBuffer hs = new StringBuffer();
		String stmp = "";
		for (int n = 0; n < b.length; n++) {
			stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
			if (stmp.length() == 1)
				hs.append("0").append(stmp);
			else
				hs.append(stmp);
		}
		return hs.toString().toUpperCase();
	}
	public static void main(String[] args) throws Exception {
	/*	MessageDigest md = MessageDigest.getInstance("MD5");
		String result1 = byte2hex(md.digest("1234bar2baz中文foo1".getBytes("utf-8")));
    	System.out.println(result1);
		
		String result = Util.getResult(testUrl,testUserGet());
    	 System.out.print(result);*/
    	 
     	 //String mark = "dd{ddd}dd";
    	// mark = mark.replaceFirst("{.}", "zgw");
    	// System.out.println("mark="+mark);
    	 String aa = "222.000";
    	 Double bb= Double.parseDouble(aa);
    

	}
}
